# Maintainer: Ignacio Casal Quinteiro <icq@gnome.org>

_realname=libgusb
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.6
pkgrel=2
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
pkgdesc="GLib wrapper around libusb1 (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-libusb"
         "${MINGW_PACKAGE_PREFIX}-libssp"
         "${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
options=('strip' '!debug' 'staticlibs')
license=("LGPL")
url="https://github.com/hughsie/libgusb"
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/hughsie/${_realname}/archive/${pkgver}.tar.gz"
        fix-build.patch
        introspection-optional.patch
        windows-lld-no-version-script.patch)
sha256sums=('b81b4587243beaafd304fec6047cb803b47f5df382911d4f722ffcfe7239bd59'
            'a3f23ea5e84d6c369492526670d38f0fb77d57a9e93df20d143d079dc6c2cbb8'
            '0b59e9915d2e8a64d1aee378ac925c6bdbfc45b1960a6f6e9d3843a447c27c85'
            '5d97cfbecae68849d9d2af889af43748e9d3ded1e8eaf8e3eb1068aeb9059f0b')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/fix-build.patch
  patch -p1 -i ${srcdir}/introspection-optional.patch
  patch -p1 -i ${srcdir}/windows-lld-no-version-script.patch
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  CFLAGS+=" -fstack-protector"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    --buildtype plain \
    -Dintrospection=true \
    -Dvapi=true \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install
}
